package org.charles.zhifou.model.vo;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.charles.zhifou.enums.UserRoleEnum;
import org.charles.zhifou.model.entity.User;
import org.springframework.beans.BeanUtils;

import java.io.Serial;
import java.io.Serializable;
import java.util.Date;

/**
 * 已登录用户视图（脱敏）-> 这个 VO 有必要存在嘛 ?
 *
 * @author charles
 * @version 1.0
 **/
@Data
public class LoginUserVO implements Serializable {

    @Schema(description = "用户 id")
    private Long id;

    @Schema(description = "用户昵称")
    private String userName;

    @Schema(description = "用户头像")
    private String userAvatar;

    @Schema(description = "用户简介")
    private String userProfile;

    @Schema(description = "用户角色: 0-普通用户, 1-管理员, 2-被封号")
    private UserRoleEnum userRole;

    @Schema(description = "创建时间")
    private Date createTime;

    @Schema(description = "更新时间")
    private Date updateTime;

    @Serial
    private static final long serialVersionUID = 1L;


    /**
     * VO 转实体类
     * @param loginUserVO
     * @return
     */
    public static User voToEntity(LoginUserVO loginUserVO) {
        if (loginUserVO == null) {
            return null;
        }

        User user = new User();
        BeanUtils.copyProperties(loginUserVO, user);

        return user;
    }

    /**
     * 实体类转 VO
     * @param user
     * @return
     */
    public static LoginUserVO entityToVo(User user) {
        if (user == null) {
            return null;
        }

        LoginUserVO userVO = new LoginUserVO();
        BeanUtils.copyProperties(user, userVO);

        return userVO;
    }
}